package com.gopay.common.core.dic.dao.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.core.dic.dao.DicBankRetCodeQueryDAO;
import com.gopay.common.domain.dic.DicBankRetCode;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 银行返回码字典查询DAO实现类
 * DicBankRetCodeQueryDAOImpl.java
 * @author sh.jiao
 * @2017-8-2 上午10:27:20  www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("dicBankRetCodeQueryDAO")
public class DicBankRetCodeQueryDAOImpl extends BaseDAOImpl<DicBankRetCode,Serializable> implements DicBankRetCodeQueryDAO {

    @Override
    public String translateBankRetCode(String bankCode,String bankRetCode) {
        String retMsg = "";
        if(bankCode != null && !"".equals(bankCode)
                && bankRetCode != null && !"".equals(bankRetCode)) {
            String hql = "FROM DicBankRetCode t WHERE t.bankAbbr=:bankCode AND t.bankRetCode=:bankRetCode";
            Map<String,Object> queryParam = new HashMap<>();
            queryParam.put("bankCode",bankCode);
            queryParam.put("bankRetCode",bankRetCode);
            List<DicBankRetCode> list = findByHql(hql,queryParam);
            if(list != null && !list.isEmpty()) {
                DicBankRetCode code = list.get(0);
                retMsg = code.getCodeMsg();
            } else {
                retMsg = DicBankRetCode.DEFAULT_NOT_FOUND_CODE_MSG;
            }
        }
        return retMsg;
    }
}
